package com.abe.jmcl.android.retrofit.presenter;


import com.abe.jmcl.android.retrofit.contract.CommonContract;
import com.abe.jmcl.android.retrofit.contract.CommonModel;
import com.abe.jmcl.entity.http.test.HttpBaseReturnModel;
import com.abe.jmcl.entity.http.test.HttpUserInfoEntity;
import com.abeframe.core.base.MVPBaseLogPresenter;
import com.abeframe.core.base.http.ResultListener;

public class CommonPresenter extends MVPBaseLogPresenter<CommonContract.ServiceTestView> implements CommonContract.ServiceTestPresenter {
    private CommonContract.Model model;

    public CommonPresenter() {
        model = new CommonModel();
    }

    @Override
    public void getData() {
        model.getData(new ResultListener<HttpBaseReturnModel<HttpUserInfoEntity>>() {
            @Override
            public void onStart() {

            }

            @Override
            public void onEnd() {
                if (isViewAttached()) {
                    getView().onFinish(XmlCityPresenter.class.getSimpleName());
                } else {
                    showViewAttachedError();
                }
            }

            @Override
            public void onSuccess(HttpBaseReturnModel<HttpUserInfoEntity> data) {
                if (isViewAttached()) {
                    if (data != null) {
                        getView().onGetData(data.result);
                    } else {
                        showViewDataNullError();
                    }
                } else {
                    showViewAttachedError();
                }
            }

            @Override
            public void onFailure(String message) {
                if (isViewAttached()) {
                    getView().showMessage(0, message);
                    getView().onFaild(XmlCityPresenter.class.getSimpleName());
                } else {
                    showViewAttachedError();
                }
            }
        });
    }
}
